package com.corpgovernment.job.dao.mapper;

import com.corpgovernment.job.dao.entity.db.JobOrgRelationDo;
import com.corpgovernment.job.enums.DeletedEnum;
import com.corpgovernment.organization.common.mybatis.TkMapper;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ldma
 * @date 2024/1/18
 */
public interface JobOrgRelationMapper extends TkMapper<JobOrgRelationDo> {

    default void batchCreate(List<JobOrgRelationDo> jobOrgRelationDoList) {
        this.insertList(jobOrgRelationDoList);
    }

    default void removeByJobId(Long jobId) {
        if (jobId == null) {
            return;
        }
        JobOrgRelationDo jobOrgRelationDo = new JobOrgRelationDo();
        jobOrgRelationDo.setDeleted(DeletedEnum.TRUE.getCode());
        Example example = new Example(JobOrgRelationDo.class);
        example.createCriteria().andEqualTo("jobId", jobId).andEqualTo("deleted", DeletedEnum.FALSE.getCode());
        this.updateByExampleSelective(jobOrgRelationDo, example);
    }

    default List<JobOrgRelationDo> listByJobIdList(List<Long> jobIdList) {
        if (CollectionUtils.isEmpty(jobIdList)) {
            return new ArrayList<>(0);
        }
        Example example = new Example(JobOrgRelationDo.class);
        example.createCriteria().andIn("jobId", jobIdList).andEqualTo("deleted", DeletedEnum.FALSE.getCode());
        return this.selectByExample(example);
    }

    default List<JobOrgRelationDo> listAll() {
        Example example = new Example(JobOrgRelationDo.class);
        example.createCriteria().andEqualTo("deleted", DeletedEnum.FALSE.getCode());
        return this.selectByExample(example);
    }

    default List<JobOrgRelationDo> listJobByOrgId(String orgId) {
        Example example = new Example(JobOrgRelationDo.class);
        example.createCriteria().andEqualTo("orgId", orgId).andEqualTo("deleted", DeletedEnum.FALSE.getCode());
        return this.selectByExample(example);
    }

}
